package mylist
{
	import com.greensock.TweenLite;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.media.CameraUI;
	
	/**
	 * ...
	 * @author db0@qq.com
	 */
	public class MultiUploadBtns extends Sprite
	{
		public static var header:Bitmap;
		public static var main:MultiUploadBtns;
		
		[Embed(source="../asset/photobtn.png")]
		private var EnterBmpd:Class;
		private var photoBtn:Sprite = new Sprite();
		
		public function MultiUploadBtns()
		{
			if (main)
				return;
			main = this;
			photoBtn.addChild(new EnterBmpd());
			addChild(photoBtn);
			photoBtn.buttonMode = true;
			photoBtn.name = "upload";
			photoBtn.addEventListener(MouseEvent.CLICK, clicked);
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		public function showHear():void
		{
			TweenLite.killTweensOf(header);
			TweenLite.to(header, .3, {y: 0});
		}
		
		public function hideHear():void
		{
			TweenLite.killTweensOf(header);
			TweenLite.to(header, .3, {y: -header.height});
		}
		
		private function init(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			[Embed(source="../asset/topbar.png")]
			var Header:Class;
			header = new Header() as Bitmap;
			//header.width = Math.max(stage.stageWidth, stage.stageHeight);
			addChild(header);
			header.y = -header.height;
			header.x = stage.stageWidth / 2 -header.width/2;
			
			photoBtn.x = stage.stageWidth / 2 - photoBtn.width / 2;
			photoBtn.y = stage.stageHeight - photoBtn.height*.8;
		}
		
		private function clicked(e:MouseEvent):void
		{
			if (CameraUI.isSupported)
			{
				if (AndroidCamera.main) {
					AndroidCamera.main.init();
				}else {
					stage.addChild(new AndroidCamera);
				}
			}
			else
			{
				if (MyCam.main) {
					stage.addChild(MyCam.main);
				}else {
					stage.addChild(new MyCam);
				}
				if (MyCam.video.visible)
				{
					MyCam.main.savepic(null);
				}
				else
				{
					MyCam.main.startCam();
				}
				
			}
		}
	
	}

}